<template>
	<div class="fix_a white">   
	    <div class="input">
				<van-cell-group>
				  <van-field v-model="params.addressRealName" placeholder="请输入收货人姓名" label="收货人"/>			  
				</van-cell-group>	
				<van-cell-group>
				  <van-field v-model="params.addressMobile" placeholder="请输入收货人联系电话" label="手机号"/>
				</van-cell-group>
				
				<van-cell-group>
				  <van-field v-model="params.addressAreaInfo" placeholder="请选择地区"  right-icon="arrow"
				  	label="地区选择" readonly  @click="showArea"/>
				</van-cell-group>			
			
	    	
				<van-cell-group>
					<van-field
					  v-model="params.address"
					  rows="5"
					  autosize
					  label="详细地址"
					  type="textarea"
					  placeholder="请输入详细地址"
					  
					/>
				</van-cell-group>
	
		    </div>



        <floor46 ref="floor46" @query="selectArea"></floor46>



	    <div class="fixB" >
	    	<van-button type="primary"  class="bottom" :loading="loading" @click="save">保存地址</van-button>
	    </div>
	</div>	
</template>

<script>
import areaList from '@/api/area.js'
import {getFun} from '@/api/publicFun.js'	
import Floor46 from '_c/market/floor/floor46.vue'	
let publicFun=getFun()	
export default {
	components: {
	     Floor46
	},		
	data() {
       return {
       	 loading:false,
       	 show:false,// 显示地区选择
       	 areaList:areaList,   // 地区选择的数据文件
         url3:this.$api+'/marketorderservice/api/v1/market/marketRelease/address/add', // 新增地址接口
         params:{
					address:'',           // 详细地址 ,
					addressAreaId1:'',    // 一级地区Id ,
					addressAreaId2:'',    // 二级地区Id ,
					addressAreaId3:'',    // 三级地区Id ,
					addressIsDefault:1,  // 是否是默认收货地址(0-否，1-是) ,
					addressMobile:'',     // 手机 ,
					addressRealName:'',   // 收货人姓名 ,
					memberId:'',          // 会员Id     
					addressAreaInfo:''    // 拼接地区 
         }
       }
	},
	props:["memberId"],
	methods: {
		showArea(){
				this.$refs.floor46.show()
		},
	  // 确认省市区
    selectArea(arr){
    	this.params.addressAreaId1=arr[0].code
    	this.params.addressAreaId2=arr[1].code
    	this.params.addressAreaId3=arr[2].code
    	let title=arr[0].name+' '+ arr[1].name +' ' + arr[2].name 
    	this.params.addressAreaInfo=title
    },
    save(){        	
    	if(!this.regTel(this.params.addressMobile)){
    		this.$toast('请输入正确的电话号码')
    		return false
    	}        	
    	if(this.params.addressAreaId1==''||this.params.addressAreaId2==''||this.params.addressAreaId3==''){
    		this.$toast('请选择省市区')
    		return false
    	}
    	if(!this.params.address){
    		this.$toast('详细地址不能为空')
    		return false        		
    	}
    	if(!this.params.addressRealName){
    		this.$toast('收货人姓名不能为空')
    		return false        		
    	}        
    	this.params.memberId=this.memberId
      this.loading=true
      let that=this	     
      this.$Axios3.Post(this.url3,this.params).then(function(res) {
         that.$toast('操作成功')               
         that.loading=false
         that.$emit('addSuccess')
      })	            
    }
	},
	mixins:[publicFun],//混入		
	mounted() {

	}
}	
</script>

<style scoped lang="scss">
.bottom{background: $bc1;border: none;width: 100%;border-radius: 0;color: #333;font-size: 16px;font-weight: 500;}
.fixB{padding: 20px 37.5px;position: fixed;bottom: 0;left: 0;width: 100%;box-sizing: border-box;background: #fff;z-index: 1000;}

.input{padding-bottom: 100px;}
.defaultWrap{display: flex;padding: 10px 15px;align-items: center;}
.defaultWrap .left{width: 80%;}
.defaultWrap .right{flex: 1;display: flex;justify-content: flex-end;}
</style>